#include<bits/stdc++.h>
using namespace std;
int T,n,a[200005];
long long ans;
void dfs(int idx,int r,int b,long long c){
    if(idx==n){
        ans=max(ans,c+(a[r]==a[idx]?a[r]:0));
        ans=max(c+(a[b]==a[idx]?a[b]:0),ans);
        return ;
    }
    dfs(idx+1,idx,b,c+(a[r]==a[idx]?a[r]:0));
    dfs(idx+1,r,idx,c+(a[b]==a[idx]?a[b]:0));
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        ans=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",a+i);
        dfs(1,0,0,0);
        printf("%lld\n",ans);
    }
    return 0;
}
